home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mnp_c.zip / FCSCALC.ASM < prev    next >
Assembly Source File  |  1990-05-16  |  2KB  |  99 lines

  1.     title    fcscalc.asm
  2.     page    60,132
  3. ;==============================================================================
  4. ;
  5. ;                     The Microcom MNP Library
  6. ;                    (Microsoft C Version)
  7. ;
  8. ;------------------------------------------------------------------------------
  9. ;
  10. ;    fcscalc - calculate frame check sequence
  11. ;
  12. ;    synopsis: 
  13. ;        
  14. ;            fcscalc(fcs_word,octet);
  15. ;
  16. ;    input:
  17. ;            struct {char low, hi;}  *fcs_word;
  18. ;            char octet;
  19. ;
  20. ;==============================================================================
  21.  
  22. _data     segment word public 'DATA'
  23. _data    ends
  24. dgroup    group    _data
  25.  
  26. _data    segment 
  27. temp    db    ?            ; temp variable
  28. _data    ends
  29.  
  30. _text    segment byte public 'CODE'
  31.     assume     cs:_text,ds:dgroup
  32.  
  33.     public    _fcscalc
  34.  
  35. fcs    =    4
  36. octet    =    6
  37. hi    =    1
  38. ;
  39. ;
  40. _fcscalc proc    near
  41.  
  42.     push    bp
  43.     mov    bp,sp
  44. ;
  45.     push    ax
  46.     push    bx
  47.     push    cx
  48.     push    si
  49. ;
  50.     mov    ax,[bp+octet]    ;get octet
  51.     mov    si,[bp+fcs]
  52.     xor    al,[si+hi]    ;hi byte of resulting fcs number
  53.     mov    temp,al
  54.     mov    bl,al
  55. ;
  56.     mov    cx,7
  57. lp1:
  58.     sar    bl,1
  59.     add    al,bl
  60.     loop    lp1
  61. ;
  62.     and    al,01h
  63.     mov    bl,temp
  64.     sar    al,1
  65.     rcr    bl,1
  66.     rcr    al,1
  67.     sar    bl,1
  68.     rcl    bl,1
  69.     pushf                ;save carry flag
  70.     xor    bl,temp
  71.  
  72. ;    popf                    ;recover carry flag
  73.     jmp    $+3                ; simulate popf
  74.     iret
  75.     push    cs
  76.     call    cs:$-2
  77.  
  78.     rcr    bl,1
  79.     rcr    al,1
  80.     sar    bl,1
  81.     rcl    bl,1
  82.     adc    al,00h
  83.     xor    al,[si]             ;low byte of result
  84.     mov    [si],bl             ;save new low byte
  85.     mov    [si+hi],al        ;save new hi byte
  86. ;
  87.     pop    si
  88.     pop    cx
  89.     pop    bx
  90.     pop    ax
  91. ;
  92.     pop    bp
  93.     ret
  94. ;
  95. _fcscalc endp
  96.  
  97. _text    ends
  98.     end
  99.